package com.meida.module.bus.provider.service.srmservice;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.meida.common.mybatis.base.service.impl.BaseServiceImpl;
import com.meida.module.bus.client.entity.srmapi.basedata.SrmProjectinfoSqlSer;
import com.meida.module.bus.provider.mapper.srm.SrmProjectinfoSqlSerMapper;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * SRM项目信息表接口实现类
 *
 * @author both
 * @date 2020-10-14
 */
@Service
@DS("dbr")
public class SrmSqlserService  {
    @Autowired
    private JdbcTemplate jdbcTemplate;

    public Object getDatas(String tableNm, Class name) {
        String sqlCount = "select count(*) from " + tableNm;
        Long count = jdbcTemplate.queryForObject(sqlCount, Long.class);
        if(0L == count) {
            return new ArrayList<>();
        }

        BeanPropertyRowMapper<Object> rowMapper = new BeanPropertyRowMapper<>(name);
        String sqlContent = "select * from " + tableNm;
        return jdbcTemplate.query(sqlContent, rowMapper);
    }

//    public List<SrmProjectinfoSqlSer> getProjects() {
//        String sqlCount = "select count(*) from B_BP_PROJECTINFO";
//        Long count = jdbcTemplate.queryForObject(sqlCount, Long.class);
//        if(0L == count) {
//            return null;
//        }
//        BeanPropertyRowMapper<SrmProjectinfoSqlSer> rowMapper = new BeanPropertyRowMapper<>(SrmProjectinfoSqlSer.class);
//        String sqlContent = "select * from B_BP_PROJECTINFO";
//        List<SrmProjectinfoSqlSer> uiList = jdbcTemplate.query(sqlContent, rowMapper);
//        return jdbcTemplate.query(sqlContent, rowMapper);
//    }
}
